<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>编辑二级栏目</title>
<link href="${backPath}/images/skin.css" rel="stylesheet"
	type="text/css" />

<script type="text/javascript" src="${appPath}/common/common.js"></script>

<!-- FCKeditor 2.6.5-->	
<script type="text/javascript" src="/card/fckeditor/fckeditor.js"></script>
<script type="text/javascript" language="javascript">
	//加载CKEditor
	function init() {		
		var editor = new FCKeditor('section.fileContent','100%','400');
		editor.BasePath = "/card/fckeditor/";
		editor.ReplaceTextarea();		
		/*var fileContentTArea = document.getElementById("section.fileContent");
		var dynamicCheck = document.getElementById("dynamicCheck");
		var sectionTitle = document.getElementById("section.title");
		var sectionFileName = document.getElementById("section.fileName");
		var staticFileName = document.getElementById("staticFileName");
		var staticTitle = document.getElementById("staticTitle");
		var dynamicTitle = document.getElementById("dynamicTitle");
		var dynamicFileName = document.getElementById("dynamicFileName");
		var checkStatus = "${section.status}";
		var fileName = "${section.fileName}";
		var lastSlashIndex = fileName.lastIndexOf("/");
		var lastDotIndex = fileName.lastIndexOf(".");
		if(checkStatus == "on"){
			dynamicCheck.checked = true;
			dynamicFileName.value = fileName.substring(lastSlashIndex + 1,lastDotIndex);
			sectionFileName.value = dynamicFileName.value;
			dynamicTitle.value = dynamicFileName.options[dynamicFileName.selectedIndex].text;
			sectionTitle.value = dynamicFileName.value;
		}else{
			dynamicCheck.checked = false;
			staticTitle.value = "${section.title}";
			sectionTitle.value = "${section.title}";			
			staticFileName.value = fileName.substring(lastSlashIndex + 1,lastDotIndex);
			sectionFileName.value = staticFileName.value;			
		}					
		changeState(dynamicCheck);*/		
	}
	//改变页面状态
	function changeState(isDynamicCheck){
		var ckeditorDiv = document.getElementById("ckeditorDiv");
		var dynamicSelectDiv = document.getElementById("dynamicSelectDiv");
		var titleDiv = document.getElementById("titleDiv");				
		if(isDynamicCheck.checked){
			dynamicSelectDiv.style.display="block";
			titleDiv.style.display="none";
			ckeditorDiv.style.display = "none";
			
		}else{
			dynamicSelectDiv.style.display="none";
			titleDiv.style.display="block";
			ckeditorDiv.style.display = "block";
		}		
	}
	//设置栏目标题隐藏域
	function setSectionFileName(sectionSelect){
		var title = sectionSelect.options[sectionSelect.selectedIndex].text;
		document.getElementById("dynamicTitle").value = title;
	}

	//提交二级栏目信息
	function editLevelTwo(){		
		//清空错误信息
		document.getElementById("errorMsgTd").innerHTML = "";		
		var isDynamicCheck = document.getElementById("dynamicCheck");
		var sectionTitleHidden = document.getElementById("section.title");
		var sectionFileNameHidden = document.getElementById("section.fileName");
		var dynamicTxt = document.getElementById("dynamicTitle");
		var staticTxt = document.getElementById("staticTitle");
		var dynamicFileName = document.getElementById("dynamicFileName");
		var staticFileName = document.getElementById("staticFileName");		
		if(isDynamicCheck.checked){
			sectionTitleHidden.value = dynamicTxt.value.trim();
			sectionFileNameHidden.value = dynamicFileName.value.trim();
		}else{
			sectionTitleHidden.value = staticTxt.value.trim();
			sectionFileNameHidden.value = staticFileName.value.trim();
		}		
		//检查用户提交的信息
		//检查标题内容是否为空!		
		/*if(sectionTitleHidden.value.length == 0){
			alert("二级栏目的标题不能为空！");
			return false;
		}*/
		//检查文件名是否合法
		/*if(sectionFileNameHidden.value.length == 0){
			alert("二级栏目的文件名不能为空！");
			return false;
		}*/
		/*if(!/^[a-zA-Z0-9]+$/g.test(sectionFileNameHidden.value)){
			alert("二级栏目的文件名只能是字母和数字的组合！");
			return false;
		}*/
		//检查栏目内容是否为空		
		if(!isDynamicCheck.checked){
			var fileContentData = FCKeditorAPI.GetInstance('section.fileContent').GetXHTML().trim();	
			if(fileContentData.length == 0){
				alert("二级栏目对应的页面内容不能为空！");
				return false;
			}			
		}
		var form = getLevelTwoForm();
		form.action = "${backPath}/setup/editLevelTwo.action";	
		form.submit();
	}

	//获得levelTwoForm
	function getLevelTwoForm(){
		return document.getElementById("levelTwoForm");
	}
	
	//返回二级栏目列表页
	function backToLevelTwos(){
		var form = getLevelTwoForm();
		document.getElementById("section.sectionId").value = 
			document.getElementById("section.parentId").value;
		form.action = "${backPath}/setup/listLevelTwo.action";
		form.submit();
	}
	
</script>
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	background-color: #EEF2FB;
}
-->
</style>
</head>
<body onload="init();">
<form id="levelTwoForm" name="levelTwoForm" 
	method="post" >
<table width="100%" border="0" cellpadding="0" cellspacing="0">
	<tr>
		<td width="17" valign="top"
			background="${backPath}/images/mail_leftbg.gif"><img
			src="${backPath}/images/left-top-right.gif" width="17" height="29" /></td>
		<td valign="top" background="${backPath}/images/content-bg.gif">
		<table width="100%" height="31" border="0" cellpadding="0"
			cellspacing="0" class="left_topbg" id="table2">
			<tr>
				<td height="31">
				<div class="titlebt">更新栏目</div>
				</td>
			</tr>
		</table>
		</td>
		<td width="16" valign="top"
			background="${backPath}/images/mail_rightbg.gif"><img
			src="${backPath}/images/nav-right-bg.gif" width="16" height="29" /></td>
	</tr>
	<tr>
		<td valign="middle" background="${backPath}/images/mail_leftbg.gif">&nbsp;</td>
		<td valign="top" bgcolor="#F7F8F9">
		<table width="98%" border="0" align="center" cellpadding="0"
			cellspacing="0" bgcolor="#E2E7ED">
			<tr>
				<td colspan="2" valign="top">&nbsp;</td>
			</tr>
			<tr>
				<td colspan="2" valign="top"><!--HTML-->
				<table class=main_tab id=mainTable cellspacing=0 cellpadding=0
					width=100% border=0>
					<!--TBODY-->
					<tbody>
						<tr>
							<td valign="middle">
							<table width="98%" border="0" align="center" cellpadding="0"
								cellspacing="0" bgcolor="#E2E7ED">
								<tbody>
									<tr>
										<td width="4%" height="20" bgcolor="#F7F8F9"></td>
										<td height="40" colspan="2" width="" bgcolor="#F7F8F9"
											align="center">更新二级栏目${section.title}的内容</td>
									</tr>
									<tr>										
										<td height="40" colspan="3" width="" bgcolor="#F7F8F9"
											align="center" class="left_txt" id="errorMsgTd"><font color="red"><s:actionerror/></font></td>
									</tr>
									<tr>
										<td width="4%" height="20" bgcolor="#F7F8F9"></td>
										<td height="40" colspan="2" width="" bgcolor="#F7F8F9"
											class="left_txt">是否是动态页面: <input id="dynamicCheck"
											type="checkbox" name="dynamicCheck" onclick="changeState(this)"/>
										&nbsp;&nbsp;
										<div id="dynamicSelectDiv" style="display: none"><s:select
											list="levelTwoDynamicPageInfoMap" headerKey=""
											headerValue="请选择动态页面" name="dynamicFileName"
											id="dynamicFileName" cssClass="left_txt"
											onchange="setSectionFileName(this)">
										</s:select> <%-- 保存选中动态页面所属的目录 --%> <input id="dynamicTitle"
											type="hidden" size="20" /></div>
										</td>
									</tr>
									<tr class="left_txt" id="staticPageTr">
										<td bgcolor="#FAFBFC">&nbsp;</td>
										<td height="" colspan="2" align="" valign="middle"
											bgcolor="#FAFBFC">
										<div id="titleDiv">栏目标题: ${section.title}
										   <input type="hidden" name="staticTitle" id="staticTitle" value="${section.title}"/>
											&nbsp;&nbsp;
											文件名：${section.fileName}
											<input type="hidden" name="staticFileName" id="staticFileName" value="${section.fileName}"/>
										</div>
										<div id="ckeditorDiv" style="margin-top: 10px"><textarea
											name="section.fileContent" id="section.fileContent">${section.fileContent}</textarea></div>
										</td>
									</tr>
									<tr class="left_txt">
										<td bgcolor="#FAFBFC">&nbsp;</td>
										<td width="42%" height="25" bgcolor="#FAFBFC">&nbsp;</td>
										<td width="54%" height="25" bgcolor="#FAFBFC"><span
											class="left_txt"> <font color="#FFFFFF"
											class="left_ts"><b> <input type="button" value="保存"
											onclick="editLevelTwo()"> &nbsp; <input type="button" value="返回二级栏目列表页"
											onclick="backToLevelTwos()" /></b></font></span></td>
									</tr>
									<tr>
										<td height="5" colspan="3"></td>
									</tr>
								</tbody>
							</table>
							</td>
						</tr>
					</tbody>
				</table>
				</td>
			</tr>
		</table>
		</td>
		<td background="${backPath}/images/mail_rightbg.gif">&nbsp;</td>
	</tr>
	<tr>
		<td valign="bottom" background="${backPath}/images/mail_leftbg.gif"><img
			src="${backPath}/images/buttom_left2.gif" width="17" height="17" /></td>
		<td background="${backPath}/images/buttom_bgs.gif"><img
			src="${backPath}/images/buttom_bgs.gif" width="17" height="17"></td>
		<td valign="bottom" background="${backPath}/images/mail_rightbg.gif"><img
			src="${backPath}/images/buttom_right2.gif" width="16" height="17" /></td>
	</tr>
</table>
<%-- 二级栏目编号隐藏域 --%> <input id="section.sectionId"
	name="section.sectionId" type="hidden" value="${section.sectionId}" />
<%-- 二级栏目所属一级栏目编号隐藏域 --%> <input id="section.parentId"
	name="section.parentId" type="hidden" value="${section.parentId}" /> 
<%-- 二级栏目标题隐藏域--%>
<input id="section.title" name="section.title" type="hidden" />
<%-- 二级栏目文件名隐藏域--%>
<input id="section.fileName" name="section.fileName" type="hidden" />
</form>
</body>
</html>